

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>Java Swift Examples &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="Python Swift 实例" href="../python/" />
    <link rel="prev" title="Tutorial" href="../tutorial/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../">Ceph 对象网关</a> &raquo;</li>
        
          <li><a href="../">Ceph 对象网关 Swift API</a> &raquo;</li>
        
      <li>Java Swift Examples</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../../_sources/radosgw/swift/java.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 对象网关</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../frontends/">HTTP 前端</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../placement/">存储池归置与存储类</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multisite/">多站配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multisite-sync-policy/">多站同步策略配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pools/">存储池的配置</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../config-ref/">配置参考</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../admin/">管理指南</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../s3/">S3 API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../rgw-cache/">Data caching and CDN</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">Swift API</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="../#api">API</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="../auth/">认证</a></li>
<li class="toctree-l4"><a class="reference internal" href="../serviceops/">服务操作</a></li>
<li class="toctree-l4"><a class="reference internal" href="../containerops/">容器操作</a></li>
<li class="toctree-l4"><a class="reference internal" href="../objectops/">对象操作</a></li>
<li class="toctree-l4"><a class="reference internal" href="../tempurl/">临时 URL 操作</a></li>
<li class="toctree-l4"><a class="reference internal" href="../tutorial/">指导手册</a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#">Java</a></li>
<li class="toctree-l4"><a class="reference internal" href="../python/">Python</a></li>
<li class="toctree-l4"><a class="reference internal" href="../ruby/">Ruby</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../#id1">功能支持</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../adminops/">管理操作 API</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">Python 接口</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../nfs/">通过 NFS 导出</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../keystone/">与 OpenStack Keystone 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../barbican/">与 OpenStack Barbican 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../vault/">与 HashiCorp Vault 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../kmip/">KMIP Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../opa/">与 Open Policy Agent 对接</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../multitenancy/">多租户</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../compression/">压缩</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ldap-auth/">LDAP 认证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../encryption/">服务器端加密</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../bucketpolicy/">桶策略</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../dynamicresharding/">动态的桶索引重分片</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../mfa/">多因子认证</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../sync-modules/">同步模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../notifications/">Bucket Notifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../layout/">RADOS 中的数据布局</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../STS/">STS</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../STSLite/">STS Lite</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../keycloak/">Keycloak</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../role/">Role</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../session-tags/">Session Tags</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../orphans/">Orphan List and Associated Tooliing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../oidc/">OpenID Connect Provider</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../man/8/radosgw/">radosgw 手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../man/8/radosgw-admin/">radosgw-admin 手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../qat-accel/">使用 QAT 为加密和压缩提速</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../s3select/">S3-select</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../lua-scripting/">Lua Scripting</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../d3n_datacache/">D3N Data Cache</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-transition/">Cloud Transition</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="java-swift-examples">
<span id="java-swift"></span><h1>Java Swift Examples<a class="headerlink" href="#java-swift-examples" title="Permalink to this headline">¶</a></h1>
<div class="section" id="id1">
<h2>配置<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<p>The following examples may require some or all of the following Java
classes to be imported:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">org.javaswift.joss.client.factory.AccountConfig</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.javaswift.joss.client.factory.AccountFactory</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.javaswift.joss.client.factory.AuthenticationMethod</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.javaswift.joss.model.Account</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.javaswift.joss.model.Container</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.javaswift.joss.model.StoredObject</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">java.io.File</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">java.io.IOException</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">java.util.*</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="section" id="id2">
<h2>建立一个连接<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>This creates a connection so that you can interact with the server:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">String</span> <span class="n">username</span> <span class="o">=</span> <span class="s">&quot;USERNAME&quot;</span><span class="p">;</span>
<span class="n">String</span> <span class="n">password</span> <span class="o">=</span> <span class="s">&quot;PASSWORD&quot;</span><span class="p">;</span>
<span class="n">String</span> <span class="n">authUrl</span>  <span class="o">=</span> <span class="s">&quot;https://radosgw.endpoint/auth/1.0&quot;</span><span class="p">;</span>

<span class="n">AccountConfig</span> <span class="n">config</span> <span class="o">=</span> <span class="k">new</span> <span class="n">AccountConfig</span><span class="p">();</span>
<span class="n">config</span><span class="p">.</span><span class="na">setUsername</span><span class="p">(</span><span class="n">username</span><span class="p">);</span>
<span class="n">config</span><span class="p">.</span><span class="na">setPassword</span><span class="p">(</span><span class="n">password</span><span class="p">);</span>
<span class="n">config</span><span class="p">.</span><span class="na">setAuthUrl</span><span class="p">(</span><span class="n">authUrl</span><span class="p">);</span>
<span class="n">config</span><span class="p">.</span><span class="na">setAuthenticationMethod</span><span class="p">(</span><span class="n">AuthenticationMethod</span><span class="p">.</span><span class="na">BASIC</span><span class="p">);</span>
<span class="n">Account</span> <span class="n">account</span> <span class="o">=</span> <span class="k">new</span> <span class="n">AccountFactory</span><span class="p">(</span><span class="n">config</span><span class="p">).</span><span class="na">createAccount</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>创建一个容器<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>This creates a new container called <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">container</span><span class="p">.</span><span class="na">create</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="create-an-object">
<h2>Create an Object<a class="headerlink" href="#create-an-object" title="Permalink to this headline">¶</a></h2>
<p>This creates an object <code class="docutils literal notranslate"><span class="pre">foo.txt</span></code> from the file named <code class="docutils literal notranslate"><span class="pre">foo.txt</span></code> in
the container <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">StoredObject</span> <span class="n">object</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">);</span>
<span class="n">object</span><span class="p">.</span><span class="na">uploadObject</span><span class="p">(</span><span class="k">new</span> <span class="n">File</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="add-update-object-metadata">
<h2>Add/Update Object Metadata<a class="headerlink" href="#add-update-object-metadata" title="Permalink to this headline">¶</a></h2>
<p>This adds the metadata key-value pair <code class="docutils literal notranslate"><span class="pre">key</span></code>:<code class="docutils literal notranslate"><span class="pre">value</span></code> to the object named
<code class="docutils literal notranslate"><span class="pre">foo.txt</span></code> in the container <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">StoredObject</span> <span class="n">object</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">);</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">metadata</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TreeMap</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">metadata</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="s">&quot;key&quot;</span><span class="p">,</span> <span class="s">&quot;value&quot;</span><span class="p">);</span>
<span class="n">object</span><span class="p">.</span><span class="na">setMetadata</span><span class="p">(</span><span class="n">metadata</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="list-owned-containers">
<h2>List Owned Containers<a class="headerlink" href="#list-owned-containers" title="Permalink to this headline">¶</a></h2>
<p>This gets a list of Containers that you own.
This also prints out the container name.</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Collection</span><span class="o">&lt;</span><span class="n">Container</span><span class="o">&gt;</span> <span class="n">containers</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">list</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="n">Container</span> <span class="n">currentContainer</span> <span class="p">:</span> <span class="n">containers</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">currentContainer</span><span class="p">.</span><span class="na">getName</span><span class="p">());</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The output will look something like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mahbuckat1</span>
<span class="n">mahbuckat2</span>
<span class="n">mahbuckat3</span>
</pre></div>
</div>
</div>
<div class="section" id="list-a-container-s-content">
<h2>List a Container’s Content<a class="headerlink" href="#list-a-container-s-content" title="Permalink to this headline">¶</a></h2>
<p>This gets a list of objects in the container <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>; and, it also
prints out each object’s name, the file size, and last modified date:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">Collection</span><span class="o">&lt;</span><span class="n">StoredObject</span><span class="o">&gt;</span> <span class="n">objects</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">list</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="n">StoredObject</span> <span class="n">currentObject</span> <span class="p">:</span> <span class="n">objects</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="n">currentObject</span><span class="p">.</span><span class="na">getName</span><span class="p">());</span>
<span class="p">}</span>
</pre></div>
</div>
<p>The output will look something like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">myphoto1</span><span class="o">.</span><span class="n">jpg</span>
<span class="n">myphoto2</span><span class="o">.</span><span class="n">jpg</span>
</pre></div>
</div>
</div>
<div class="section" id="retrieve-an-object-s-metadata">
<h2>Retrieve an Object’s Metadata<a class="headerlink" href="#retrieve-an-object-s-metadata" title="Permalink to this headline">¶</a></h2>
<p>This retrieves metadata and gets the MIME type for an object named <code class="docutils literal notranslate"><span class="pre">foo.txt</span></code>
in a container named <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">StoredObject</span> <span class="n">object</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">);</span>
<span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">returnedMetadata</span> <span class="o">=</span> <span class="n">object</span><span class="p">.</span><span class="na">getMetadata</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="n">String</span> <span class="n">name</span> <span class="p">:</span> <span class="n">returnedMetadata</span><span class="p">.</span><span class="na">keySet</span><span class="p">())</span> <span class="p">{</span>
    <span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">&quot;META / &quot;</span><span class="o">+</span><span class="n">name</span><span class="o">+</span><span class="s">&quot;: &quot;</span><span class="o">+</span><span class="n">returnedMetadata</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">name</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="retrieve-an-object">
<h2>Retrieve an Object<a class="headerlink" href="#retrieve-an-object" title="Permalink to this headline">¶</a></h2>
<p>This downloads the object <code class="docutils literal notranslate"><span class="pre">foo.txt</span></code> in the container <code class="docutils literal notranslate"><span class="pre">my-new-container</span></code>
and saves it in <code class="docutils literal notranslate"><span class="pre">./outfile.txt</span></code>:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">StoredObject</span> <span class="n">object</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">);</span>
<span class="n">object</span><span class="p">.</span><span class="na">downloadObject</span><span class="p">(</span><span class="k">new</span> <span class="n">File</span><span class="p">(</span><span class="s">&quot;outfile.txt&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="delete-an-object">
<h2>Delete an Object<a class="headerlink" href="#delete-an-object" title="Permalink to this headline">¶</a></h2>
<p>This deletes the object <code class="docutils literal notranslate"><span class="pre">goodbye.txt</span></code> in the container “my-new-container”:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">StoredObject</span> <span class="n">object</span> <span class="o">=</span> <span class="n">container</span><span class="p">.</span><span class="na">getObject</span><span class="p">(</span><span class="s">&quot;foo.txt&quot;</span><span class="p">);</span>
<span class="n">object</span><span class="p">.</span><span class="na">delete</span><span class="p">();</span>
</pre></div>
</div>
</div>
<div class="section" id="delete-a-container">
<h2>Delete a Container<a class="headerlink" href="#delete-a-container" title="Permalink to this headline">¶</a></h2>
<p>This deletes a container named “my-new-container”:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Container</span> <span class="n">container</span> <span class="o">=</span> <span class="n">account</span><span class="p">.</span><span class="na">getContainer</span><span class="p">(</span><span class="s">&quot;my-new-container&quot;</span><span class="p">);</span>
<span class="n">container</span><span class="p">.</span><span class="na">delete</span><span class="p">();</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The container must be empty! Otherwise it won’t work!</p>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../python/" class="btn btn-neutral float-right" title="Python Swift 实例" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../tutorial/" class="btn btn-neutral float-left" title="Tutorial" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>